package com.example.add8_17.base;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public abstract class BaseObserver<T> implements Observer<T> {
    private BaseModel model;
    private Disposable disposable;
    @Override
    public void onSubscribe(Disposable d) {
        this.disposable=d;
        model.addDiposable(d);
    }
    public BaseObserver(BaseModel model1){
        this.model=model1;
    }
    @Override
    public void onNext(T t) {
        onSuccess(t);
        model.removeDisposable(disposable);
    }

    protected abstract void onSuccess(T t);

    @Override
    public void onError(Throwable e) {
        onFali(e.getMessage());
    }

    protected abstract void onFali(String message);

    @Override
    public void onComplete() {

    }
}
